// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Element/CTETRAParser.h"

#include "gtest/gtest.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
using namespace SG::DataStructure::FEM;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class CTETRAParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (CTETRAParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "CTETRA   70589  19074783 20197   20219   20198   21478" };

    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCTETRA (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::CTETRA4Data data;

    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (0, data);

    ASSERT_TRUE (data.m_id == 70589);
    ASSERT_TRUE (data.m_pId == 19074783);
    ASSERT_TRUE (data.m_g[0] == 20197);
    ASSERT_TRUE (data.m_g[1] == 20219);
    ASSERT_TRUE (data.m_g[2] == 20198);
    ASSERT_TRUE (data.m_g[3] == 21478);
}

TEST_F (CTETRAParserTest, ParseEntry2)
{
    std::vector<std::string> Entry = { "CTETRA         1       2       1       2       3       4      12      25+000005F",
                                       "+000005F      14      15      26      31" };

    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCTETRA (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::CTETRA10Data data;

    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (0, data);

    ASSERT_TRUE (data.m_id == 1);
    ASSERT_TRUE (data.m_pId == 2);
    ASSERT_TRUE (data.m_g[0] == 1);
    ASSERT_TRUE (data.m_g[1] == 2);
    ASSERT_TRUE (data.m_g[2] == 3);
    ASSERT_TRUE (data.m_g[3] == 4);
    ASSERT_TRUE (data.m_g[4] == 12);
    ASSERT_TRUE (data.m_g[5] == 25);
    ASSERT_TRUE (data.m_g[6] == 14);
    ASSERT_TRUE (data.m_g[7] == 15);
    ASSERT_TRUE (data.m_g[8] == 26);
    ASSERT_TRUE (data.m_g[9] == 31);
}
